package com.whnk.web.controller.pm;

import java.util.Arrays;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.SusdInfo;
import com.whnk.pm.service.ISusdInfoService;

/**
 * 补助基本 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-07-24
 */
@Controller
@RequestMapping("/pm/susdInfo")
public class SusdInfoController extends BaseController
{
    private String prefix = "pm/susdInfo";
	
	@Autowired
	private ISusdInfoService susdInfoService;
	
	@RequiresPermissions("pm:susdInfo:view")
	@GetMapping()
	public String susdInfo()
	{
	    return prefix + "/susdInfo";
	}
	
	/**
	 * 查询补助基本列表
	 */
	@RequiresPermissions("pm:susdInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SusdInfo susdInfo)
	{
		startPage();
        List<SusdInfo> list = susdInfoService.selectSusdInfoList(susdInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增补助基本
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存补助基本
	 */
	@RequiresPermissions("pm:susdInfo:add")
	@Log(title = "补助基本", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SusdInfo susdInfo)
	{		
		return toAjax(susdInfoService.insertSusdInfo(susdInfo));
	}

	/**
	 * 修改补助基本
	 */
	@GetMapping("/edit/{susdId}")
	public String edit(@PathVariable("susdId") Integer susdId, ModelMap mmap)
	{
		SusdInfo susdInfo = susdInfoService.selectSusdInfoById(susdId);
		mmap.put("susdInfo", susdInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存补助基本
	 */
	@RequiresPermissions("pm:susdInfo:edit")
	@Log(title = "补助基本", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SusdInfo susdInfo)
	{		
		return toAjax(susdInfoService.updateSusdInfo(susdInfo));
	}
	
	/**
	 * 删除补助基本
	 */
	@RequiresPermissions("pm:susdInfo:remove")
	@Log(title = "补助基本", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(susdInfoService.deleteSusdInfoByIds(ids));
	}
	
	/**
	 * 查看详细信息
	 * 
	 * @param susdId
	 * @param mmap
	 * @return
	 */
	@RequiresPermissions("pm:susdInfo:detail")
    @GetMapping("/detail/{susdId}")
    public String detail(@PathVariable("susdId") Integer susdId, ModelMap mmap)
	{
		SusdInfo susdInfo = susdInfoService.selectSusdInfoById(susdId);
		mmap.put("susdInfo", susdInfo);
        return prefix + "/detail";
    }
	
	/**
	 * 查看补助明细信息
	 * 
	 * @param susdId
	 * @param mmap
	 * @return
	 */
	@GetMapping("/queryDetail/{susdId}")
    public String queryDetail(@PathVariable("susdId") Integer susdId, ModelMap mmap)
    {
		SusdInfo susdInfo = susdInfoService.selectSusdInfoById(susdId);
		mmap.put("susdInfo", susdInfo);
        return "pm/susdDetail/susdDetail";
    }
	
	@Log(title = "生成补助明细", businessType = BusinessType.OTHER)
	@PostMapping("/genSusdDetail")
	@ResponseBody
    public AjaxResult genSusdDetail(String ids) {
		List<String> listId = Arrays.asList(ids.split(","));
		susdInfoService.genSusdDetail(listId);
		return success();
	}
}
